// pages/components/cancle_orde/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: ''
    },
    types:{
      type: Object,
      value: null
    }
  },
  observers:{
    types:function(obj){
      var arr = [];
      for(let i in obj) {
        console.log(i,obj[i])
        if(i == 1){
          arr.push ({
            name: obj[i],
            checked: true
          })
        }else{
          arr.push ({
            name: obj[i],
            checked: false
          })
        }
      }
      this.setData({
        reasonList:arr,
        explain: arr[0]?.name || ''
      })
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    reasonList: [{
        name: '送货到家',
        checked: true
      },
      {
        name: '暂放',
        checked: false
      }
    ],
    explain:'送货到家',
    imageFiles:[]
  },
  ready() {

  },
  /**
   * 组件的方法列表
   */
  methods: {
    closeReason() {
      this.triggerEvent('close')
    },
    sendUp() {
      let images = []
      let list = this.data.imageFiles || []
      if(list.length){
        list.forEach((item,index)=>{
          images.push(item.url)
        })
      }
      this.triggerEvent('send',{
        complate_type: this.data.explain,
        complate_pic: images.toString()
      })
    },
    getUploaderList(e){
      this.setData({
        imageFiles: e.detail.uploaderList,
        explain: e.detail.explain
      })
    },
    checkboxChange(e) {
      let index = e.currentTarget.dataset.index
      let reasonList = this.data.reasonList
      reasonList[index].checked = !reasonList[index].checked
      
      reasonList.forEach(function (o, i) {
        if (i != index) {
          o.checked = false
        }
      })
      this.setData({
        reasonList,
        explain:reasonList[index].name
      })
    }
  }
})